package fr.lelouet.tools

import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class Main {
	
	private static final Logger logger = LoggerFactory.getLogger(Main.class)
	
	static void getProperties(String[] mainArgs, Properties prop) {		
		mainArgs.each { 
			String arg = (String) it;
			if(! arg.startsWith("-")) {
				try {
					prop.load(new FileInputStream(arg));
				} catch(FileNotFoundException e) {
					logger.error("could not load properties from {}", arg)
				}
			} else {
				String[] atts = arg.split ("=");
				if(atts.size() == 2) {
					prop.setProperty atts[0].substring(1), atts[1];
				} else {
					logger.error ("argument ${arg} does not respect -<key>=<value> : discarded")
				}
			}
		}
	}
}
